package pers.yurwisher.rubick.common.security;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import pers.yurwisher.rubick.common.service.CustomRedisCacheService;

/**
 *
 * @author yq
 * @date 2021/04/22 20:31
 * @since V1.0.0 在 UsernamePasswordAuthenticationFilter 之前注册过滤器
 * @description
 */
@Slf4j
@RequiredArgsConstructor
public class TokenSecurityConfigurerAdapter extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

    private final TokenProvider tokenProvider;
    private final CustomRedisCacheService customRedisCacheService;

    @Override
    public void configure(HttpSecurity http) {
        TokenFilter customFilter = new TokenFilter(tokenProvider,customRedisCacheService);
        log.info("add TokenFilter before UsernamePasswordAuthenticationFilter");
        http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class);
    }
}
